package com.xinyue.game.server.system;

import com.xinyue.network.codec.GameCodecFactory;
import com.xinyue.network.codec.GameMessageContext;
import com.xinyue.network.message.ChannelConfirmMessageRequest;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

@ChannelHandler.Sharable
public class DecodeHandler extends ChannelInboundHandlerAdapter {


    public DecodeHandler() {
        //添加系统消息
        GameCodecFactory.addMessageClass(ChannelConfirmMessageRequest.class);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf byteBuf = (ByteBuf) msg;
        GameMessageContext gameMessageContext = GameCodecFactory.readMessage(byteBuf);
        ctx.fireChannelRead(gameMessageContext);
    }
}
